﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FacebookWrapper.ObjectModel;
using Ex3.FriendSelector;

namespace Ex3
{
    public partial class FriendsSelectorForm : Form
    {
        public IStrategy Strategy { get; private set; }

        public FriendsSelectorForm(List<User> i_Friends)
        {
            this.InitializeComponent();
        }

        private void buttonSelect_Click(object sender, EventArgs e)
        {
            this.getSelectedStrategy();
            this.Close();
        }

        private void getSelectedStrategy()
        {
            foreach (RadioButton currentRadio in this.Controls.OfType<RadioButton>())
            {
                if (currentRadio.Checked)
                {
                    if (currentRadio == this.radioButtonAge)
                    {
                        this.Strategy = new AgeStrategy((int)this.numericUpDownMin.Value, (int)this.numericUpDownMax.Value);
                    }
                    else if (currentRadio == this.radioButtonSingle)
                    {
                        this.Strategy = new SingleStrategy(this.checkBoxSingle.Checked);
                    }
                    else if (currentRadio == this.radioButtonGender)
                    {
                        this.Strategy = new GenderStrategy(this.checkBoxFemale.Checked);
                    }
                }
            }
        }

        public void orderSelection(RadioButton i_Selected)
        {
            foreach (RadioButton currentRadio in this.Controls.OfType<RadioButton>())
            {
                if (currentRadio != i_Selected)
                {
                    currentRadio.Checked = false;
                }
            }
        }

        private void radioButtonSingle_Click(object sender, EventArgs e)
        {
            this.orderSelection(this.radioButtonSingle);
            this.checkBoxSingle.Enabled = true;
        }

        private void radioButtonAge_Click(object sender, EventArgs e)
        {
            this.orderSelection(this.radioButtonAge);
            this.panelAge.Enabled = true;
        }

        private void radioButtonGender_Click(object sender, EventArgs e)
        {
            this.orderSelection(this.radioButtonGender);
            this.panelGender.Enabled = true;
        }

        private void radioButtonAge_CheckedChanged(object sender, EventArgs e)
        {
            if (!this.radioButtonAge.Checked)
            {
                this.panelAge.Enabled = false;
            }
        }

        private void radioButtonSingle_CheckedChanged(object sender, EventArgs e)
        {
            if (!this.radioButtonSingle.Checked)
            {
                this.checkBoxSingle.Enabled = false;
            }
        }

        private void radioButtonGender_CheckedChanged(object sender, EventArgs e)
        {
            if (!this.radioButtonGender.Checked)
            {
                this.panelGender.Enabled = false;
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void numericUpDownMin_ValueChanged(object sender, EventArgs e)
        {
            if (this.numericUpDownMax.Value < this.numericUpDownMin.Value)
            {
                this.numericUpDownMax.Value = this.numericUpDownMin.Value;
            }
        }

        private void numericUpDownMax_ValueChanged(object sender, EventArgs e)
        {
            if (this.numericUpDownMax.Value < this.numericUpDownMin.Value)
            {
                this.numericUpDownMin.Value = this.numericUpDownMax.Value;
            }
        }

        private void checkBoxMale_CheckedChanged(object sender, EventArgs e)
        {
            if (this.checkBoxMale.Checked)
            {
                this.checkBoxMale.Enabled = false;
                this.checkBoxFemale.Checked = false;
                this.checkBoxFemale.Enabled = true;
            }
        }

        private void checkBoxFemale_CheckedChanged(object sender, EventArgs e)
        {
            if (this.checkBoxFemale.Checked)
            {
                this.checkBoxFemale.Enabled = false;
                this.checkBoxMale.Checked = false;
                this.checkBoxMale.Enabled = true;
            }
        }
    }
}
